package org.bjou

import org.grails.plugins.excelimport.*
import org.bjou.*

import static org.grails.plugins.excelimport.ExpectedPropertyType.*


class ExcelImporter extends AbstractExcelImporter {

    static Map CONFIG_BOOK_CELL_MAP = [ 
        sheet:'Sheet2', 
        cellMap: [ 'D3':'title',
        'D4':'author',
        'D6':'numSold',
        ]
    ] 
 
    static Map CONFIG_BOOK_COLUMN_MAP = [
        sheet:'Sheet1', 
        startRow: 0,
        columnMap:  [
                  'A':'ruleCode',
                  'B':'majorName',
                  'C':'courseName',
                  'D':'courseType',
                  'E':'courseId'
        ]
    ]
    static Map CONFIG_COURSE_COLUMN_MAP = [
        sheet:'专业规则总表', 
        startRow: 1,
        columnMap:  [
                  'A':'ruleCode',
                  'B':'majorName',
                  'C':'courseId',
                  'D':'courseName',
                  'E':'credit',
                  'F':'courseType',
                  'G':'courseProperty',
                  'H':'examType',
                  'I':'courseTerm',
                  'J':'examNumber',
                  'K':'examNumberB',
                  'L':'departmentName' ,
                  'M':'majorLevel',
                  'N':'courseStatus',
                  'O':'entryTerm'
         ]
    ]
    
    
    static Map CONFIG_COURSE_NEW_COLUMN_MAP = [
        sheet:'统招高职总表', 
        startRow: 1,
        columnMap:  [
                  'A':'ruleCode',
                  'B':'majorName',
                  'C':'courseId',
                  'D':'courseName',
                  'E':'credit',
                  'F':'courseType',
                  'G':'courseProperty',
                  'H':'examType',
                  'I':'courseTerm',
                  'J':'examNumber',
                  'K':'examNumberB',
                  'L':'departmentName',
                  'M':'majorLevel',
                  'N':'courseStatus',
                  'O':'entryTerm'
         ]
    ]
    
  
    
     static Map CONFIG_COURSERULE_COLUMN_MAP = [
        sheet:'专业规则适用年度', 
        startRow: 1,
        columnMap:  [
                  'A':'ruleId',
                  'B':'ruleType',
                  'C':'majorLevel',
                  'D':'majorName',
                  'E':'ruleCode',
                  'F':'ruleSet',
                  'G':'ruleYear',
                  'H':'ruleSeason'
                  
        ]
    ]
    
    
    def getExcelImportService() {
		ExcelImportService.getService()
	}

    public ExcelImporter(fileName) {
        super(fileName)
    }

    List<Map> getBooks() {
         List bookList = excelImportService.columns(workbook, CONFIG_BOOK_COLUMN_MAP)
        //List bookList = ExcelImportUtils.convertColumnMapConfigManyRows(workbook, CONFIG_BOOK_COLUMN_MAP)
    }
    
    List<Map> getCourseList() {
         List courseList = excelImportService.columns(workbook, CONFIG_COURSE_COLUMN_MAP)
        //print courseList
        //List bookList = ExcelImportUtils.convertColumnMapConfigManyRows(workbook, CONFIG_BOOK_COLUMN_MAP)
    }
    
    
     List<Map> getCourseNewList() {
         Map propertyConfigurationMap = [
                 courseId:([expectedType: StringType, defaultValue:null])
         ]
         List courseList = excelImportService.columns(workbook, CONFIG_COURSE_NEW_COLUMN_MAP,null, propertyConfigurationMap)
        //print courseList
        //List bookList = ExcelImportUtils.convertColumnMapConfigManyRows(workbook, CONFIG_BOOK_COLUMN_MAP)
    }
    
    List<Map> getCourseRuleList() {
         List courseList = excelImportService.columns(workbook, CONFIG_COURSERULE_COLUMN_MAP)
        //List bookList = ExcelImportUtils.convertColumnMapConfigManyRows(workbook, CONFIG_BOOK_COLUMN_MAP)
    }


    Map getOneMoreBookParams() {
       // Map bookParams = ExcelImportUtils.convertFromCellMapToMapWithValues(workbook, CONFIG_BOOK_CELL_MAP )
        Map bookParams = excelImportService.cells(workbook, CONFIG_BOOK_COLUMN_MAP )
    }

}

